<?php
$urlParams = array("table/Default_Model_DbTable_AuditLog");


foreach(Zend_Controller_Front::getInstance()->getRequest()->getUserParams() as $key => $value)
{
	$urlParams[] = urlencode($key) . '/' . urlencode($value);
}
$urlParams = implode('/', $urlParams);
?>
<h1><?= $this->table->getNiceName() ?> List</h1>


<div id="record_list_menu" class="yuimenubar yuimenubarnav">
	<div class="bd">
		<ul class="first-of-type">
			<li class="yuimenubaritem first-of-type">
				<a class="yuimenuitemlabel" href="<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/add/<?= str_replace('/useLayout/false', '', $urlParams)?>">
					Add New <?= $this->table->getNiceName() ?>
				</a>
			</li>
		</ul>
	</div>
</div>
		
		
<script type="text/javascript">
viewRecord = function(oArgs)
{
	var target = oArgs.target;
    var targetRow = this.getTrEl(target);
    if (targetRow)
	{
		var targetRecord = this.getRecord(targetRow);

		var newUrl = '<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/view/table/<?= $this->tableName?>/';
	<?php
		foreach($this->table->info(Bushido_Db_Table_Abstract::PRIMARY) as $pk)
		{
			echo "newUrl += '${pk}/' + targetRecord.getData()['$pk'] + '/';\n";
		}
	?>
		
		
		//newModalDialog({title: 'Detail', style: 'width:770px;', href: newUrl});
		window.location = newUrl;
	}
	return;
	
}

	rowsetLayout = <?= Zend_Json::encode($this->table->getGridLayout()) ?>;

</script>


<div id="record_list_data_table">
	
</div>
<script type="text/javascript">
	(
		function()
		{
			var recordListMenuBar = new YAHOO.widget.MenuBar('record_list_menu');
			recordListMenuBar.render();
			
			var recordsetDataSource = new YAHOO.util.DataSource("<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/json/<?= $urlParams ?>?");
			recordsetDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
			recordsetDataSource.connXhrMode = "queueRequests";
			recordsetDataSource.responseSchema =
			{
				resultsList: "records",
				fields: rowsetLayout,
				metaFields: {totalRecords: "totalRecords"}
			};

			var recordsetDataTableConfig =
			{
				draggableColumns:true,
				dynamicData: true,
				paginator: new YAHOO.widget.Paginator({ rowsPerPage:30 })
			};
			
			var recordsetDataTable = new YAHOO.widget.DataTable("record_list_data_table", rowsetLayout, recordsetDataSource, recordsetDataTableConfig);
			
			recordsetDataTable.subscribe("rowMouseoverEvent", recordsetDataTable.onEventHighlightRow);
	        recordsetDataTable.subscribe("rowMouseoutEvent", recordsetDataTable.onEventUnhighlightRow);
	        recordsetDataTable.subscribe("rowClickEvent", viewRecord);

	        recordsetDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload)
	        {
				oPayload.totalRecords = oResponse.meta.totalRecords; 
				return oPayload; 
			};
		}
	)();

</script>
